package com.hzhc.controller.baseinfo;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hzhc.annotation.SysTemLog;
import com.hzhc.common.BaseController;
import com.hzhc.entity.Station;
import com.hzhc.enumBean.ResultUtilCodeEnum;
import com.hzhc.service.StationService;
import com.hzhc.utils.ResultUtil;
import com.hzhc.utils.TokenUtil;
import com.hzhc.vo.StationVo;
import lombok.RequiredArgsConstructor;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 站点信息 前端控制器
 * </p>
 *
 * @author 1
 * @since 2024-05-30
 */
@RestController
@RequestMapping("/station")
@RequiredArgsConstructor
public class StationController extends BaseController {

    private final StationService stationService;

    /**
     * 站点列表 list
     * @param request
     * @param vo
     * @return
     */
    @RequestMapping("/getStationList")
    @ResponseBody
    public ResultUtil<List<StationVo>> getStationList(HttpServletRequest request, @RequestBody StationVo vo){
        Page<StationVo> page = new Page<>(vo.getPageIndex(),vo.getPageSize());
        List<StationVo> list = stationService.getStationList(page,vo);
        return ResultUtil.build(list,page.getTotal(),page.getPages(), ResultUtilCodeEnum.SUCCESS);
    }

    /**
     * 站点管理 add
     * @param request
     * @param station
     * @return
     */
    @PostMapping("/addStation")
    @SysTemLog(operModul = "基础信息-站点维护",operType = "ADD",operDesc = "站点维护添加",modular="PC")
    public ResultUtil<T> addStation(HttpServletRequest request,@RequestBody Station station){
        Long userID = TokenUtil.getUserID(request);
        station.setUserId(userID.intValue());
        station.setCreateTime(LocalDateTime.now());
        return stationService.addStation(station);
    }

    /**
     * 站点check
     * @param station
     * @return
     */
    @PostMapping("/checkStation")
    public ResultUtil<T> checkStation(@RequestBody Station station){
        Boolean b = stationService.checkStation(station);
        if (b){
            return ResultUtil.ok();
        }
        return ResultUtil.build(ResultUtilCodeEnum.STATION_EXIST);
    }

    /**
     * 站点管理 update
     * @param request
     * @param station
     * @return
     */
    @PostMapping("/updateStation")
    @SysTemLog(operModul = "基础信息-站点维护",operType = "UPDATE",operDesc = "站点维护修改",modular="PC")
    public ResultUtil<T> updateStation(HttpServletRequest request,@RequestBody Station station){
        Long userID = TokenUtil.getUserID(request);
        station.setUpdateUserId(userID.intValue());
        station.setUpdateTime(LocalDateTime.now());
        return stationService.updateStation(station);
    }

    /**
     * 站点管理 delete
     * @param id
     * @return
     */
    @GetMapping("/delStation/{id}")
    @SysTemLog(operModul = "基础信息-站点维护",operType = "ADD",operDesc = "站点维护删除",modular="PC")
    public ResultUtil<T> delStation(@PathVariable Long id){
        return stationService.delStation(id);
    }

}
